package com.alimentamais.app.form;

import javax.swing.JFrame;
import java.awt.Color;
import java.awt.EventQueue;
import javax.swing.JLabel;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.JRadioButton;
import javax.swing.border.EmptyBorder;
import javax.swing.JScrollPane;
import javax.swing.JButton;
import javax.swing.JSeparator;

public class HistoricoForm extends JFrame {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private JPanel contentPane;
	private JTextField txtDia;
	private JTextField txtMs;
	private JTextField txtAno;
	private JTextField txtAno_1;
	private JTextField txtMs_1;
	private JTextField txtDia_1;
	private JLabel lblDeterminar;
	private JRadioButton rdbtnInicio;
	private JRadioButton rdbtnFim;
	private JLabel lblPrimeiraReceitaValidada;
	private JLabel lblUltimaReceitaValidada;
	private JRadioButton rdbtnHorario;
	private JLabel lblDia;
	private JLabel lblHora;
	private JTextField txtDeH;
	private JTextField txtDeMin;
	private JTextField txtDeS;
	private JTextField txtAtH;
	private JTextField txtAtMin;
	private JTextField txtAtS;
	private JSeparator separator;
	private JLabel lblDe_1;
	private JLabel lblAt_1;
	
	
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					HistoricoForm frame = new HistoricoForm();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	
	public HistoricoForm() {
		setTitle("Hist\u00F3rico");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 550, 400);
		getContentPane().setBackground(Color.BLACK);
		getContentPane().setForeground(Color.WHITE);
		
		contentPane = new JPanel();
		contentPane.setBackground(Color.BLACK);
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		
		JLabel lblEscolhaOIntervalo = new JLabel("Escolha o intervalo:");
		lblEscolhaOIntervalo.setBounds(10, 11, 522, 14);
		lblEscolhaOIntervalo.setHorizontalAlignment(SwingConstants.CENTER);
		lblEscolhaOIntervalo.setForeground(Color.WHITE);
		lblEscolhaOIntervalo.setFont(new Font("Tahoma", Font.BOLD, 11));
		
		JLabel lblDe = new JLabel("De:");
		lblDe.setBounds(10, 96, 28, 14);
		lblDe.setHorizontalTextPosition(SwingConstants.CENTER);
		lblDe.setForeground(Color.WHITE);
		lblDe.setFont(new Font("Tahoma", Font.BOLD, 11));
		
		JLabel lblAt = new JLabel("At\u00E9:");
		lblAt.setBounds(10, 124, 28, 14);
		lblAt.setForeground(Color.WHITE);
		lblAt.setFont(new Font("Tahoma", Font.BOLD, 11));
		
		txtDia = new JTextField();
		txtDia.setVisible(false);
		txtDia.setBounds(48, 93, 33, 20);
		txtDia.setText("Dia");
		txtDia.setColumns(10);
		
		txtMs = new JTextField();
		txtMs.setVisible(false);
		txtMs.setBounds(87, 93, 33, 20);
		txtMs.setText("M\u00EAs");
		txtMs.setColumns(10);
		
		txtAno = new JTextField();
		txtAno.setVisible(false);
		txtAno.setBounds(126, 93, 62, 20);
		txtAno.setText("Ano");
		txtAno.setColumns(10);
		
		txtAno_1 = new JTextField();
		txtAno_1.setVisible(false);
		txtAno_1.setBounds(126, 124, 62, 20);
		txtAno_1.setText("Ano");
		txtAno_1.setColumns(10);
		
		txtMs_1 = new JTextField();
		txtMs_1.setVisible(false);
		txtMs_1.setBounds(87, 124, 33, 20);
		txtMs_1.setText("M\u00EAs");
		txtMs_1.setColumns(10);
		
		txtDia_1 = new JTextField();
		txtDia_1.setVisible(false);
		txtDia_1.setBounds(48, 124, 33, 20);
		txtDia_1.setText("Dia");
		txtDia_1.setColumns(10);
		
		lblPrimeiraReceitaValidada = new JLabel("Primeira receita validada");
		lblPrimeiraReceitaValidada.setForeground(Color.WHITE);
		lblPrimeiraReceitaValidada.setFont(new Font("Tahoma", Font.BOLD, 11));
		lblPrimeiraReceitaValidada.setBounds(48, 96, 204, 14);
		getContentPane().add(lblPrimeiraReceitaValidada);
		
		lblUltimaReceitaValidada = new JLabel("\u00DAltima receita validada");
		lblUltimaReceitaValidada.setForeground(Color.WHITE);
		lblUltimaReceitaValidada.setFont(new Font("Tahoma", Font.BOLD, 11));
		lblUltimaReceitaValidada.setBounds(48, 127, 204, 14);
		getContentPane().add(lblUltimaReceitaValidada);
		
		lblDeterminar = new JLabel("Determinar:");
		lblDeterminar.setBounds(10, 40, 81, 14);
		lblDeterminar.setForeground(Color.WHITE);
		lblDeterminar.setFont(new Font("Tahoma", Font.BOLD, 11));
		
		rdbtnInicio = new JRadioButton("Data inicial");
		rdbtnInicio.setBounds(109, 36, 92, 23);
		rdbtnInicio.setFont(new Font("Tahoma", Font.BOLD, 11));
		rdbtnInicio.setBackground(Color.BLACK);
		rdbtnInicio.setForeground(Color.WHITE);
		
		rdbtnFim = new JRadioButton("Data final");
		rdbtnFim.setBounds(203, 36, 92, 23);
		rdbtnFim.setForeground(Color.WHITE);
		rdbtnFim.setFont(new Font("Tahoma", Font.BOLD, 11));
		rdbtnFim.setBackground(Color.BLACK);
		
		rdbtnHorario = new JRadioButton("Hor\u00E1rio");
		rdbtnHorario.setVisible(false);
		rdbtnHorario.setForeground(Color.WHITE);
		rdbtnHorario.setFont(new Font("Tahoma", Font.BOLD, 11));
		rdbtnHorario.setBackground(Color.BLACK);
		rdbtnHorario.setBounds(297, 36, 92, 23);
		contentPane.add(rdbtnHorario);
		
		rdbtnInicio.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if (rdbtnInicio.isSelected()==true) {
					
					txtDia.setVisible(true);
					txtMs.setVisible(true);
					txtAno.setVisible(true);
					
					txtDia.setText("Dia");
					txtMs.setText("M\u00EAs");
					txtAno.setText("Ano");
					lblPrimeiraReceitaValidada.setVisible(false);
					
					txtDeH.setText("00");
					txtDeMin.setText("00");
					txtDeS.setText("00");
					txtAtH.setText("23");
					txtAtMin.setText("59");
					txtAtS.setText("59");
					rdbtnHorario.setVisible(true);
					rdbtnHorario.setSelected(false);
				}
				else {
					rdbtnHorario.setVisible(false);
					txtDia.setVisible(false);
					txtMs.setVisible(false);
					txtAno.setVisible(false);
					lblPrimeiraReceitaValidada.setVisible(true);
					configurarHora(false);
				}
			}
		});
		
		rdbtnFim.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if (rdbtnFim.isSelected()==true) {
					
					txtDia_1.setVisible(true);
					txtMs_1.setVisible(true);
					txtAno_1.setVisible(true);
					
					txtDia_1.setText("Dia");
					txtMs_1.setText("M\u00EAs");
					txtAno_1.setText("Ano");
					lblUltimaReceitaValidada.setVisible(false);
					
					txtDeH.setText("00");
					txtDeMin.setText("00");
					txtDeS.setText("00");
					txtAtH.setText("23");
					txtAtMin.setText("59");
					txtAtS.setText("59");
					rdbtnHorario.setVisible(true);
					rdbtnHorario.setSelected(false);
				}
				else {
					rdbtnHorario.setVisible(false);
					txtDia_1.setVisible(false);
					txtMs_1.setVisible(false);
					txtAno_1.setVisible(false);
					lblUltimaReceitaValidada.setVisible(true);
					configurarHora(false);
				}
			}
		});
		
		rdbtnHorario.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if (rdbtnHorario.isSelected()==true) {
					
					configurarHora(true);
					txtDia_1.setText("Dia");
					txtMs_1.setText("M\u00EAs");
					txtAno_1.setText("Ano");
				}
				else {
					configurarHora(false);
				}
			}
		});
		
		JScrollPane scrollPane = new JScrollPane();
		scrollPane.setBounds(10, 220, 522, 135);
		contentPane.add(scrollPane);
		
		JLabel lblGerar = new JLabel("Receitas:");
		lblGerar.setHorizontalAlignment(SwingConstants.CENTER);
		lblGerar.setForeground(Color.WHITE);
		lblGerar.setFont(new Font("Tahoma", Font.BOLD, 11));
		lblGerar.setBounds(10, 195, 522, 14);
		contentPane.add(lblGerar);
		
		JButton btnGerar = new JButton("Gerar");
		btnGerar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
			}
		});
		btnGerar.setBounds(109, 155, 120, 29);
		contentPane.add(btnGerar);
		
		JButton btnCancelar = new JButton("Cancelar");
		btnCancelar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				
				HistoricoForm.this.dispose();
				PrincipalForm frame = new PrincipalForm();
				frame.setVisible(true);
			}
		});
		btnCancelar.setBounds(323, 155, 120, 29);
		contentPane.add(btnCancelar);
		
		lblDia = new JLabel("Dia:");
		lblDia.setHorizontalAlignment(SwingConstants.CENTER);
		lblDia.setForeground(Color.WHITE);
		lblDia.setFont(new Font("Tahoma", Font.BOLD, 11));
		lblDia.setBounds(10, 71, 251, 14);
		contentPane.add(lblDia);
		
		lblHora = new JLabel("Hora:");
		lblHora.setVisible(false);
		lblHora.setHorizontalAlignment(SwingConstants.CENTER);
		lblHora.setForeground(Color.WHITE);
		lblHora.setFont(new Font("Tahoma", Font.BOLD, 11));
		lblHora.setBounds(281, 71, 251, 14);
		contentPane.add(lblHora);
		
		separator = new JSeparator();
		separator.setVisible(false);
		separator.setOrientation(SwingConstants.VERTICAL);
		separator.setBounds(256, 71, 2, 80);
		contentPane.add(separator);
		
		lblDe_1 = new JLabel("De:");
		lblDe_1.setVisible(false);
		lblDe_1.setHorizontalTextPosition(SwingConstants.CENTER);
		lblDe_1.setForeground(Color.WHITE);
		lblDe_1.setFont(new Font("Tahoma", Font.BOLD, 11));
		lblDe_1.setBounds(267, 99, 28, 14);
		contentPane.add(lblDe_1);
		
		lblAt_1 = new JLabel("At\u00E9:");
		lblAt_1.setVisible(false);
		lblAt_1.setForeground(Color.WHITE);
		lblAt_1.setFont(new Font("Tahoma", Font.BOLD, 11));
		lblAt_1.setBounds(267, 127, 28, 14);
		contentPane.add(lblAt_1);
		
		txtDeH = new JTextField();
		txtDeH.setVisible(false);
		txtDeH.setText("00");
		txtDeH.setColumns(10);
		txtDeH.setBounds(305, 93, 33, 20);
		contentPane.add(txtDeH);
		
		txtDeMin = new JTextField();
		txtDeMin.setVisible(false);
		txtDeMin.setText("00");
		txtDeMin.setColumns(10);
		txtDeMin.setBounds(348, 93, 33, 20);
		contentPane.add(txtDeMin);
		
		txtDeS = new JTextField();
		txtDeS.setVisible(false);
		txtDeS.setText("00");
		txtDeS.setColumns(10);
		txtDeS.setBounds(391, 93, 33, 20);
		contentPane.add(txtDeS);
		
		txtAtH = new JTextField();
		txtAtH.setVisible(false);
		txtAtH.setText("23");
		txtAtH.setColumns(10);
		txtAtH.setBounds(305, 124, 33, 20);
		contentPane.add(txtAtH);
		
		txtAtMin = new JTextField();
		txtAtMin.setVisible(false);
		txtAtMin.setText("59");
		txtAtMin.setColumns(10);
		txtAtMin.setBounds(348, 124, 33, 20);
		contentPane.add(txtAtMin);
		
		txtAtS = new JTextField();
		txtAtS.setVisible(false);
		txtAtS.setText("59");
		txtAtS.setColumns(10);
		txtAtS.setBounds(391, 124, 33, 20);
		contentPane.add(txtAtS);
		
		
		contentPane.setLayout(null);
		contentPane.add(lblEscolhaOIntervalo);
		contentPane.add(lblDeterminar);
		contentPane.add(rdbtnInicio);
		contentPane.add(rdbtnFim);
		contentPane.add(lblDe);
		contentPane.add(txtDia);
		contentPane.add(txtMs);
		contentPane.add(txtAno);
		contentPane.add(lblAt);
		contentPane.add(txtDia_1);
		contentPane.add(txtMs_1);
		contentPane.add(txtAno_1);
	}
	
	public void configurarHora(boolean vouf){
		
		lblHora.setVisible(vouf);
		separator.setVisible(vouf);
		lblDe_1.setVisible(vouf);
		lblAt_1.setVisible(vouf);
		txtDeH.setVisible(vouf);
		txtDeMin.setVisible(vouf);
		txtDeS.setVisible(vouf);
		txtAtH.setVisible(vouf);
		txtAtMin.setVisible(vouf);
		txtAtS.setVisible(vouf);
	}
}
